package cn.sxt.userscenter.head.interceptor;

import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.sxt.userscenter.common.util.ConstatFinaUtil;
import cn.sxt.userscenter.users.pojo.AUsers;

@Component("authinterceptor")
public class Authinterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		/*验证是否登录*/
		ConstatFinaUtil.LOGGER.info("----authinterceptor----");
		HttpSession session = request.getSession();
		AUsers users = (AUsers) session.getAttribute("users");
		if(users==null){
			/* 没有登录 */
			session.setAttribute("info", ConstatFinaUtil.INFO_JSON.getString("3"));
			response.sendRedirect(request.getContextPath()+"/login.htm");
			return false;
		}
		return true;
	}	
}
